<script setup lang="ts">
import { ref } from 'vue'
import { patientConsultPay } from '@/api/consult'
const show = ref(false)
// withDefaults(
//   defineProps<{
//     money: number
//   }>(),
//   {
//     money: 100
//   }
// )
const props = defineProps<{
  money: number
  orderId: string
  payCallback: string
}>()
const paymentMethod = ref<0 | 1>(1)
// 支付接口调用
/*
  1：定义api
  2:导入api
  3:点击确定要调用api
  4:处理数据类型
  5：调用完成会拿到支付的页面
      打开支付页面
  支付完成，会回跳到我们传入的地址（提前已设置好的）
*/
const submit = async () => {
  const res = await patientConsultPay({
    paymentMethod: paymentMethod.value,
    orderId: props.orderId,
    payCallback: import.meta.env.VITE_APP_PAY + props.payCallback
  })
  location.href = res.data.payUrl
  console.log(res.data.payUrl)
}

defineExpose({
  show
})
</script>

<template>
  <van-action-sheet v-model:show="show" title="选择支付方式" :closeable="false">
    <div class="pay-type">
      <p class="amount">￥{{ money }}</p>
      <van-cell-group>
        <van-cell title="微信支付" @click="paymentMethod = 0">
          <template #icon><cp-icon name="consult-wechat" /></template>
          <template #extra><van-checkbox :checked="paymentMethod === 0" /></template>
        </van-cell>
        <van-cell title="支付宝支付" @click="paymentMethod = 1">
          <template #icon><cp-icon name="consult-alipay" /></template>
          <template #extra><van-checkbox :checked="paymentMethod === 1" /></template>
        </van-cell>
      </van-cell-group>
      <div class="btn">
        <van-button type="primary" round block @click="submit"> 立即支付</van-button>
      </div>
    </div>
  </van-action-sheet>
</template>

<style lang="scss" scoped>
.pay-type {
  .amount {
    padding: 20px;
    text-align: center;
    font-size: 16px;
    font-weight: bold;
  }
  .btn {
    padding: 15px;
  }
  .van-cell {
    align-items: center;
    .cp-icon {
      margin-right: 10px;
      font-size: 18px;
    }
    .van-checkbox :deep(.van-checkbox__icon) {
      font-size: 16px;
    }
  }
}
</style>
